/**
 * 用于存放微应用，每增加一个微应用，需要在这个数组配置一下
 */
const apps: any = [
    {
        name: 'ReactApp', // app name registered
        entry: '//localhost:8000',
        container: '#container',
        activeRule: '/gen',
    },
    {
        name: 'Vue2App',
        entry: '//localhost:8001',
        container: '#container',
        activeRule: '/vue',
    }
]

import {
    registerMicroApps,
    addGlobalUncaughtErrorHandler,
    start
} from "qiankun"

/**
 * 进行微应用的注册。
 * qiankun才能识别这些微应用
 */
registerMicroApps(apps, {
    //微应用加载之前，会执行这个生命周期
    beforeLoad: (app) => {
        console.log("beforeLoad", app.name);
        return Promise.resolve()
    },
    //微应用挂载成功后执行的生命周期
    afterMount: (app) => {
        console.log("afterMount", app.name);
        return Promise.resolve()
    }
})

/**
 * 添加全局异常捕获处理器
 */
addGlobalUncaughtErrorHandler((event) => {
    console.error(event);
    const { message: msg } = event
    //加载失败的时候，判断提示
    if (msg && msg.includes("died in status LOADING_SOURCE_CODE")) {
        alert("微应用加载失败！！！！")
    }
})

export default start

